using System;
using System.IO;
using Jd.ArchitectTest.AbcCalc;
using NUnit.Framework;

namespace Jd.ArchitectTest.UnitTest.AbcCalc
{
	[TestFixture]
	public class BigInt_Fixture
	{
		[Test]
		public void Add_Test()
		{
			long a = DateTime.Now.Ticks;

			BigInt bi = new BigInt();
			bi.Add( 1 );
			Assert.AreEqual( "1", bi.ToString() );

			bi.Add( 10000 );
			Assert.AreEqual( "10001", bi.ToString() );

			bi.Add( long.MaxValue );
			Assert.AreEqual( "9223372036854785808", bi.ToString() );

			bi.Add( 1111111111111111111 );
			Assert.AreEqual( "10334483147965896919", bi.ToString() );

			bi.Add( long.MinValue );
			Assert.AreEqual( "1111111111111121111", bi.ToString() );

			bi.Add( long.MinValue + 1 );
			Assert.AreEqual( "-8112260925743654696", bi.ToString() );

			bi.Add( long.MinValue );
			Assert.AreEqual( "-17335632962598430504", bi.ToString() );

			bi.Add( new BigInt( -100, 1 ) );
			Assert.AreEqual( "-117335632962598430503", bi.ToString() );
		}

		[Test]
		public void ToString_Test()
		{
			BigInt bi;

			bi = new BigInt( 0, 1 );
			Assert.AreEqual( "1", bi.ToString() );

			bi = new BigInt( 1, 1 );
			Assert.AreEqual( "1000000000000000001", bi.ToString() );

			bi = new BigInt( -1, 1 );
			Assert.AreEqual( "-999999999999999999", bi.ToString() );

			bi = new BigInt( -1, -1 );
			Assert.AreEqual( "-1000000000000000001", bi.ToString() );
		}


		[Test]
		public void ULongDivide_Test()
		{
			ulong unit	= 1000000000000000000UL;
			ulong y		= 1999999999999999999UL;
			ulong r = y / unit;
			Assert.AreEqual( 1UL, r );

			y			= 999999999999999999UL;
			r = y / unit;
			Assert.AreEqual( 0UL, r );
		}
		
		[Test]
		[Explicit]
		public void WriteText_Test()
		{
			using( StreamWriter writer = new StreamWriter( "x.txt", false ) )
			{
				for ( ulong i = 1; i <= 100000; i++ )
				{
					writer.WriteLine( BigInt.Unit + i );
				}
				writer.Close();
			}
		}

	}
}